/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.crystalrange.files.service.impl;

import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.SearchResult;
import java.util.Date;
import java.util.List;
import org.crystalrange.files.dao.FileDao;
import org.crystalrange.files.model.File;
import org.crystalrange.files.service.FileService;
import org.crystalrange.model.User;
import org.crystalrange.service.UserService;

/**
 *
 * @author Krzysiek
 */
public class FileServiceImpl implements FileService {
    
    private FileDao fileDao;
    private UserService userService;

    public FileDao getFileDao() {
        return fileDao;
    }

    public void setFileDao(FileDao fileDao) {
        this.fileDao = fileDao;
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    
    public File create(String username) {
        User currentUser = this.userService.findByUsername(username);   
        
        File file = new File();
        file.setCreatedBy(currentUser);
        file.setCreatedDate(new Date());
        
        return file;
    }

    public boolean save(File file) {
        return this.fileDao.save(file);
    }

    public boolean remove(File file) {
        return this.fileDao.remove(file);
    }

    public File find(Long id) {
        return this.fileDao.find(id);
    }

    public List<File> findAll() {
        return this.fileDao.findAll();
    }

    public SearchResult<File> searchAndCount(Search search) {
        return this.fileDao.searchAndCount(search);
    }

    public List<File> search(Search search) {
        return this.fileDao.search(search);
    }

    public File searchUnique(Search search) {
        return this.fileDao.searchUnique(search);
    }
    
}
